package com.dongnam.quanly.common.dao;

import java.io.Serializable;
import java.util.Date;

import com.dongnam.quanly.common.model.BaseEntity;

public class ExtendedGenericDao<T, ID extends Serializable> extends GenericDao<T, ID> {
	private String userId;

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	
	@Override
	public T makePersistent(T entity) {
		if (entity instanceof BaseEntity) {
			if (((BaseEntity) entity).getCreateDate() == null) {
				((BaseEntity) entity).setCreateDate(new Date());
				((BaseEntity) entity).setCreateBy(userId);
			}

			((BaseEntity) entity).setUpdateDate(new Date());
			((BaseEntity) entity).setUpdateBy(userId);
		}
		
		return super.makePersistent(entity);
	}
	public ExtendedGenericDao(String userId) {
		super();
		this.userId = userId;
	}
	
	public ExtendedGenericDao() {
		super();
		// TODO Auto-generated constructor stub
	}

}
